package day1601;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class map {
    public static void main(String[] args) {
        Map<Integer,String> a = new HashMap<>();//数据无序
        a.put(9527,"唐伯虎");
        a.put(9528,"如花");
        a.put(0000,"zhang");
        a.put(1234,"abcd");//k相同时，v会被覆盖
        System.out.println(a);

//        a.clear();//删除全部的数据
//        System.out.println(a);
//        System.out.println(a.containsKey(9527));//是否有这个k
//        System.out.println(a.containsValue("唐伯虎"));//是否有v
//        System.out.println(a.get(9527));//返回数据
//        System.out.println(a.getOrDefault(9527,"赵子龙"));//是否有这个键
//        System.out.println(a.hashCode() );//返回哈希码
//        System.out.println(a.isEmpty());//是否为空
//        System.out.println(a.remove(9527) );//删除这个键
//        System.out.println(a.remove(9527,"唐伯虎"));//删除这个键
//        System.out.println(a.replace(9527,"赵子龙") );//替换
//        System.out.println(a.replace(9528,"如花","aoaoao") );//如果数据对，则替换
//        System.out.println(a);
//        System.out.println(a.size());//元素个数
//        System.out.println(a.values());//返回v数组
//        System.out.println(a.keySet());//返回k集合

//        Set<Integer> b = a.keySet();//map必须先转为set集合才能遍历
//        for (Integer i:b){
//            System.out.println(a.get(i));
//        }
        Set<Map.Entry<Integer,String>> b = a.entrySet();//Map.Entry--map的对象，
        for (Map.Entry c :b){
            System.out.println(c.getKey());
            System.out.println(c.getValue());
        }

    }
}
